package com.youbug.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youbug.system.entity.Announcement;
import com.youbug.system.service.IAnnouncementService;
import com.youbug.system.vo.AnnouncementVo;
import com.youbug.common.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 公告信息表 前端控制器
 * </p>
 *
 * @author youbug
 * @since 2023-04-11
 */
@RestController
@RequestMapping("/announcement")
public class AnnouncementController {

    @Autowired
    private IAnnouncementService announcementService;

    @PostMapping("/getAnsmts")
    public R<IPage<Announcement>> getAnsmts(@RequestBody AnnouncementVo announcementVo){

        IPage<Announcement> ansmtPage = announcementService.getAnnouncementPage(announcementVo);

        return R.ok(ansmtPage);
    }

    @GetMapping("/getAnsmt/{id}")
    public R<Announcement> getAnsmt(@PathVariable String id){

        Announcement announcement = announcementService.getById(id);

        return R.ok(announcement);
    }

    @PostMapping("/add")
    public R<Boolean> add(@RequestBody Announcement announcement){

        boolean save = announcementService.save(announcement);

        return  R.ok(save);
    }

    @GetMapping("/delete/{id}")
    public R<Boolean> delete(@PathVariable String  id){

        boolean remove = announcementService.removeById(id);

        return  R.ok(remove);
    }

    @PostMapping("/update")
    public R<Boolean> update(@RequestBody Announcement announcement){

        boolean save = announcementService.updateById(announcement);

        return  R.ok(save);
    }
}

